
#include "Int16.h"

#include <math.h>

// DEBUG.
#include "Debug.h"

using namespace Riccsson::System;

REGISTER_CLASS_CPP(Int16)
{

}

//---------------------------------------------------------------------------------------
int Int16::CompareTo(int* value)
{
	return _internalInt16 > *value ? 1 : _internalInt16 < *value ? -1 : 0;
}
//---------------------------------------------------------------------------------------
int Int16::CompareTo(object* value)
{
	if (!(instanceof(value, Int16)))
		return false;

	return ((Int16*)value)->_internalInt16 == _internalInt16;
}
//---------------------------------------------------------------------------------------
bool Int16::Equals(int* obj)
{
	return _internalInt16 == *obj;
}
//---------------------------------------------------------------------------------------
bool Int16::Equals(object* obj)
{
	if (!(instanceof(obj, Int16)))
		return false;

	return ((Int16*)obj)->_internalInt16 == _internalInt16;
}
//---------------------------------------------------------------------------------------
int Int16::GetHashCode()
{
	return _internalInt16;
}
//---------------------------------------------------------------------------------------
TypeCode Int16::GetTypeCode()
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int16::Parse(string* s)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int16::Parse(string* s, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int16::Parse(string* s, Globalization::NumberStyles style)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Int16::Parse(string* s, Globalization::NumberStyles style, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int16::ToString()
{
	bool isNegative(false);
	if(_internalInt16 < 0)
	{
		isNegative = true;
		_internalInt16 = -_internalInt16;
	}

	int length = (int) log10((double) _internalInt16);
	char* intToString = new char[length + 2];

	int x = _internalInt16;
	int i = (int) log10((double) x);
	while(x > 0)
	{
		intToString[i] = (x % 10) + '0';
		x = x / 10;
		i = i - 1;
	}

	intToString[length + 1] = '\0';

	if(isNegative)
	{
		char* intToString2 = new char[length + 2 + 1];
		for(int i = 1; (intToString2[i] = intToString[i-1]) != '\0'; i++);
		intToString2[0] = '-';
		delete intToString;
		intToString = intToString2;
	}

	GC_PTR<string> output( new string(intToString) );

	delete intToString;
	intToString = null;

	return output;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int16::ToString(IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int16::ToString(string* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int16::ToString(const char* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Int16::ToString(string* format, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Int16::TryParse(string* s, int out result)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Int16::TryParse(string* s, Globalization::NumberStyles style, IFormatProvider* provider, int out result)
{
	throw;
}




//----------------------------------------------------------------------------
// +
Int16 Int16::operator+ ( const Int16 value )
{
	return Int16(this->_internalInt16 + value._internalInt16);
}

//----------------------------------------------------------------------------
// -
Int16 Int16::operator- ( const Int16 value )
{
	return Int16(this->_internalInt16 - value._internalInt16);
}

//----------------------------------------------------------------------------
// *
Int16 Int16::operator* ( const Int16 value )
{
	return Int16(this->_internalInt16 * value._internalInt16);
}

//----------------------------------------------------------------------------
// /
Int16 Int16::operator/ ( const Int16 value )
{
	return Int16(this->_internalInt16 / value._internalInt16);
}
Int16 Int16::operator/ ( const int& value )
{
	return Int16(this->_internalInt16 / value);
}

//----------------------------------------------------------------------------
// %
Int16 Int16::operator% ( const Int16 value )
{
	return Int16(this->_internalInt16 % value._internalInt16);
}